﻿using System.Windows;
using System.Windows.Media.Animation;

namespace MvvmFx.Common.Helpers
{
    /// <summary>
    /// The AnimationHelper class.
    /// </summary>
    public static class AnimationHelper
    {
        /// <summary>
        /// Creates an animation.
        /// </summary>
        /// <param name="storyboard">The storyboard.</param>
        /// <param name="target">The target element.</param>
        /// <param name="targetProperty">The target property.</param>
        /// <param name="pointAnim">The point to animate between.</param>
        public static void CreateAnimation(
            Storyboard storyboard,
            DependencyObject target,
            string targetProperty,
            PointAnimation pointAnim)
        {
            storyboard.Children.Add(pointAnim);

            Storyboard.SetTarget(pointAnim, target);
            Storyboard.SetTargetProperty(pointAnim, new PropertyPath(targetProperty));
        }

        /// <summary>
        /// Creates an animation.
        /// </summary>
        /// <param name="storyboard">The storyboard.</param>
        /// <param name="target">The target element.</param>
        /// <param name="targetProperty">The target property.</param>
        /// <param name="pointAnim">The point to animate between.</param>
        /// <param name="easingFunction">The easing fusion applied to the animation.</param>
        public static void CreateAnimation(
            Storyboard storyboard,
            DependencyObject target,
            string targetProperty,
            PointAnimation pointAnim, 
            IEasingFunction easingFunction)
        {
            pointAnim.EasingFunction = easingFunction; 
            
            storyboard.Children.Add(pointAnim);

            Storyboard.SetTarget(pointAnim, target);
            Storyboard.SetTargetProperty(pointAnim, new PropertyPath(targetProperty));
        }

        /// <summary>
        /// Creates an animation.
        /// </summary>
        /// <param name="storyboard">The storyboard.</param>
        /// <param name="target">The target element.</param>
        /// <param name="targetProperty">The target property.</param>
        /// <param name="doubleAnim">The double values to animate between.</param>
        public static void CreateAnimation(
            Storyboard storyboard,
            DependencyObject target,
            string targetProperty,
            DoubleAnimation doubleAnim)
        {
            storyboard.Children.Add(doubleAnim);

            Storyboard.SetTarget(doubleAnim, target);
            Storyboard.SetTargetProperty(doubleAnim, new PropertyPath(targetProperty));
        }


        /// <summary>
        /// Creates an animation.
        /// </summary>
        /// <param name="storyboard">The storyboard.</param>
        /// <param name="target">The target element.</param>
        /// <param name="targetProperty">The target property.</param>
        /// <param name="doubleAnim">The double values to animate between.</param>
        /// <param name="easingFunction">The easing fusion applied to the animation.</param>
        public static void CreateAnimation(
            Storyboard storyboard,
            DependencyObject target,
            string targetProperty,
            DoubleAnimation doubleAnim, 
            IEasingFunction easingFunction)
        {
            doubleAnim.EasingFunction = easingFunction; 

            storyboard.Children.Add(doubleAnim);
            
            Storyboard.SetTarget(doubleAnim, target);
            Storyboard.SetTargetProperty(doubleAnim, new PropertyPath(targetProperty));
        }
        
        /// <summary>
        /// Creates an animation.
        /// </summary>
        /// <param name="storyboard">The storyboard.</param>
        /// <param name="target">The target element.</param>
        /// <param name="targetProperty">The target property.</param>
        /// <param name="anim">The point between a number of key frames.</param>
        public static void CreateAnimation(
            Storyboard storyboard,
            DependencyObject target,
            string targetProperty,
            PointAnimationUsingKeyFrames anim)
        {
            storyboard.Children.Add(anim);

            Storyboard.SetTarget(anim, target);
            Storyboard.SetTargetProperty(anim, new PropertyPath(targetProperty));
        }
    }
}